﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;

using System.Text;
using System.Windows.Forms;
using System.Reflection;
using MyTextBox.Properties;

namespace MyTextBox
{
    public partial class MyTextBox : UserControl
    {
        public MyTextBox()
        {
            InitializeComponent();
        }

        [Category("自定义"), Description("密码")]
        [Browsable(true)]
        public bool UseSystemPasswordChar
        {
            get
            {
                return ATextBox.UseSystemPasswordChar;
            }
            set
            {
                ATextBox.UseSystemPasswordChar = value;
            }
        }

        [Category("自定义"), Description("最大字符数")]
        [Browsable(true)]
        public int MaxLength
        {
            get
            {
                return ATextBox.MaxLength;
            }
            set
            {
                ATextBox.MaxLength = value;
            }
        }

        [Category("自定义"), Description("AutoCompleteCustomSource")]
        [Browsable(true)]
        public AutoCompleteStringCollection AutoCompleteCustomSource
        {
            get
            {
                return ATextBox.AutoCompleteCustomSource;
            }
            set
            {
                ATextBox.AutoCompleteCustomSource = value;
            }
        }

        [Category("自定义"), Description("AutoCompleteMode")]
        [Browsable(true)]
        public AutoCompleteMode AutoCompleteMode
        {
            get
            {
                return ATextBox.AutoCompleteMode;
            }
            set
            {
                ATextBox.AutoCompleteMode = value;
            }
        }

        [Category("自定义"), Description("AutoCompleteSource")]
        [Browsable(true)]
        public AutoCompleteSource AutoCompleteSource
        {
            get
            {
                return ATextBox.AutoCompleteSource;
            }
            set
            {
                ATextBox.AutoCompleteSource = value;
            }
        }

        protected Point marginText = new Point(3,3);
        [Category("自定义"), Description("文本到左边和上边的距离")]
        [Browsable(true)]
        public Point MarginText
        {
            get
            {
                marginText = ATextBox.Location;
                return marginText;
            }
            set
            {
                marginText = value;
                ATextBox.Location = value;
            }
        }

        protected string text = "";
        [Category("自定义"), Description("文本")]
        [Browsable(true)]
        public string Text
        {
            get
            {
                return ATextBox.Text = text;
            }
            set
            {
                text = value;
                ATextBox.Text = value;
            }
        }

        protected Font font = new Font("宋体",12, FontStyle.Regular);
        [Category("自定义"), Description("字体")]
        [Browsable(true)]
        public Font TextFont
        {
            get
            {
                return ATextBox.Font = font;
            }
            set
            {
                font = value;
                ATextBox.Font = value;
            }
        }

        Image imgTopLeft = (Image)Resources.t800_14;//窗体顶部左上角图片
        Image imgTopRight = (Image)Resources.t800_16;//窗体顶部右上角图片
        Image imgTopMiddle = (Image)Resources.t800_15;//窗体顶部中间图片

        Image imgBottomLeft = (Image)Resources.t800_21;//窗体底部左下角图片
        Image imgBottonRight = (Image)Resources.t800_23;//窗体底部右下角图片
        Image imgBottonmMiddle = (Image)Resources.t800_22;//窗体底部中间图片

        Image imgMiddleLeft = (Image)Resources.t800_18;//窗体中部左边框图片
        Image imgMiddleMid = (Image)Resources.MidDrag_Mid;
        Image imgMiddleRight = (Image)Resources.t800_20;//窗体中部右边框图片

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            
            //顶部左边
            g.DrawImage(imgTopLeft, 0, 0, imgTopLeft.Width, imgTopLeft.Height);
            //顶部右边
            g.DrawImage(imgTopRight, Width - imgTopRight.Width, 0, imgTopRight.Width, imgTopRight.Height);
            //顶部中间
            g.DrawImage(imgTopMiddle, imgTopLeft.Width, 0, Width - imgTopLeft.Width - imgTopRight.Width, imgTopMiddle.Height);
            
            //底部左边
            g.DrawImage(imgBottomLeft, 0, Height - imgBottomLeft.Height, imgBottomLeft.Width, imgBottomLeft.Height);
            //底部右边
            g.DrawImage(imgBottonRight, Width - imgBottonRight.Width, Height - imgBottonRight.Height, imgBottonRight.Width, imgBottonRight.Height);
            //底部中间
            g.DrawImage(imgBottonmMiddle, imgBottomLeft.Width, Height - imgBottonmMiddle.Height, Width - imgBottomLeft.Width - imgBottonRight.Width, imgBottonmMiddle.Height);

            //中间左边
            g.DrawImage(imgMiddleLeft, 0, imgTopLeft.Height, imgMiddleLeft.Width, Height - imgTopLeft.Height - imgBottomLeft.Height);
            //中间右边
            g.DrawImage(imgMiddleRight, Width - imgMiddleRight.Width, imgTopRight.Height, imgMiddleRight.Width, Height - imgBottomLeft.Height - imgBottonRight.Height);

        }
    }
}
